package com.ruoyi.pad.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.code.ServiceHttpCode;
import com.ruoyi.common.code.SystemHttpCode;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.qrKey.CacheQrKeyUtils;
import com.ruoyi.dgdData.domain.pad.DataDgdPadToServerDTO;
import com.ruoyi.djData.domain.pad.DataDjPadToServerDTO;
import com.ruoyi.jkcrData.domain.pad.DataJkcrPadToServerDTO;
import com.ruoyi.kyjData.domain.pad.KyjPadToServerReqDTO;
import com.ruoyi.pad.domain.KyDeviceInfo;
import com.ruoyi.pad.domain.KyPadInfo;
import com.ruoyi.pad.service.IKyDeviceInfoService;
import com.ruoyi.pad.service.IKyPadInfoService;
import com.ruoyi.pad.service.IKyTaskSubmitService;
import com.ruoyi.pidaijiData.domain.pad.DataPidaijiPadToServerDTO;
import com.ruoyi.shbData.domain.pad.ShbPadToServerDTO;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.tfjData.domain.pad.DataTfjPadToServerDTO;
import com.ruoyi.tsjData.domain.pad.DataTshjPadToServerDTO;
import com.ruoyi.wgjlcData.domain.pad.DataWgjlcPadToServerDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "各个测试App数据提交接口")
@RestController
@RequestMapping("/pad/test-data")
public class PadAppController extends BaseController {

    @Autowired
    private IKyPadInfoService kyPadInfoService;

    @Autowired
    private IKyTaskSubmitService kyTaskSubmitService;

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private IKyDeviceInfoService kyDeviceInfoService;




    /**
     * 提升机数据提交
     *
     * @return
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "submit 'tishengji' testing data")
    @Transactional
    @Anonymous
    @PostMapping(value = "/tishengji")
    public AjaxResult submitTishengji(@ApiParam(name="'tishengji' data",value="传入json格式",required=true)@RequestBody DataTshjPadToServerDTO dataTshjPadToServerDTO) {
        if (!dataTshjPadToServerDTO.getUploadType().equals("1") && !dataTshjPadToServerDTO.signOk()) {
            return AjaxResult.error(SystemHttpCode.ERROR_ILLEGAL.getCode(), "非法请求");
        }
        // 平板信息
        KyPadInfo kyPadInfoEntity = kyPadInfoService.selectKyPadInfoByPadSn(dataTshjPadToServerDTO.getPadSn());
        if (kyPadInfoEntity == null && dataTshjPadToServerDTO.getUploadType().equals("0")) {
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND.getCode(), "非法设备");
        }
        if(dataTshjPadToServerDTO.getUserId() == null  && !dataTshjPadToServerDTO.getUploadType().equals("1")){
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND_USER.getCode(), "仪器还未绑定用户");
        }
        // 判断平板上传数据接口类型信息
//        if(!"002".equals(dataTshjPadToServerDTO.getDevType())) {
//            return AjaxResult.error(ServiceHttpCode.MEDIA_DEVICE_TYPE_ERROR.getCode(), "非法上传");
//        }
        if(kyPadInfoEntity == null && !dataTshjPadToServerDTO.getUploadType().equals("0")) {
            //根据userId获取用户信息
            SysUser sysUser = sysUserService.selectUserById(Long.parseLong(dataTshjPadToServerDTO.getUserId()));
            kyPadInfoEntity = new KyPadInfo();
            kyPadInfoEntity.setDeptId(sysUser.getDeptId());
            kyPadInfoEntity.setUserId(sysUser.getUserId());
            kyPadInfoEntity.setPadSn(dataTshjPadToServerDTO.getPadSn());
            //临时绑定平板数据信息
            KyDeviceInfo kyDeviceInfo = new KyDeviceInfo();
            //绑定用户信息到平板设备中
            LoginUser loginUser = CacheQrKeyUtils.getQrCache(dataTshjPadToServerDTO.getBindKey());
            kyDeviceInfo.setDevType(dataTshjPadToServerDTO.getDevType());
            kyDeviceInfo.setAppTypes(dataTshjPadToServerDTO.getAppTypes());
            kyDeviceInfo.setDevNum(dataTshjPadToServerDTO.getDevNum());
            kyDeviceInfo.setTeamUse("0");
            kyDeviceInfo.setDeptId(sysUser.getDeptId());
            kyDeviceInfo.setUserId(sysUser.getUserId());
            kyDeviceInfo.setCreateBy(sysUser.getUserName());
            kyDeviceInfoService.insertKyDeviceInfo(kyDeviceInfo);
        }
        return AjaxResult.success(kyTaskSubmitService.submitTsjTasks(kyPadInfoEntity, dataTshjPadToServerDTO));
    }

    /**
     * 空压机数据提交
     *
     * @return
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "空压机")
    @Transactional
    @Anonymous
    @PostMapping(value = "/kongyaji")
    public AjaxResult submitKongyaji(@ApiParam(name="'kongyaji' data",value="传入json格式",required=true)@RequestBody KyjPadToServerReqDTO dataKyjVo) {
        if (!dataKyjVo.getUploadType().equals("1") && !dataKyjVo.signOk()) {
            return AjaxResult.error(SystemHttpCode.ERROR_ILLEGAL.getCode(), "非法请求");
        }
        // 平板信息
        KyPadInfo kyPadInfoEntity = kyPadInfoService.selectKyPadInfoByPadSn(dataKyjVo.getPadSn());
        if (kyPadInfoEntity == null && dataKyjVo.getUploadType().equals("0")) {
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND.getCode(), "非法设备");
        }
        if(dataKyjVo.getUserId() == null){
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND_USER.getCode(), "仪器还未绑定用户");
        }
        // 判断平板上传数据接口类型信息
//        if(!"004".equals(dataTshjPadToServerDTO.getDevType())) {
//            return AjaxResult.error(ServiceHttpCode.MEDIA_DEVICE_TYPE_ERROR.getCode(), "非法上传");
//        }
        if(dataKyjVo.getUploadType().equals("2")) {
            //根据userId获取用户信息
            SysUser sysUser = sysUserService.selectUserById(Long.parseLong(dataKyjVo.getUserId()));
            kyPadInfoEntity = new KyPadInfo();
            kyPadInfoEntity.setDeptId(sysUser.getDeptId());
            kyPadInfoEntity.setUserId(sysUser.getUserId());
            kyPadInfoEntity.setPadSn(dataKyjVo.getPadSn());
            //临时绑定平板数据信息
            KyDeviceInfo kyDeviceInfo = new KyDeviceInfo();
            //绑定用户信息到平板设备中
            LoginUser loginUser = CacheQrKeyUtils.getQrCache(dataKyjVo.getBindKey());
            kyDeviceInfo.setDevType(dataKyjVo.getDevType());
            kyDeviceInfo.setAppTypes(dataKyjVo.getAppTypes());
            kyDeviceInfo.setDevNum(dataKyjVo.getDevNum());
            kyDeviceInfo.setTeamUse("0");
            kyDeviceInfo.setDeptId(sysUser.getDeptId());
            kyDeviceInfo.setUserId(sysUser.getUserId());
            kyDeviceInfo.setCreateBy(sysUser.getUserName());
            kyDeviceInfoService.insertKyDeviceInfo(kyDeviceInfo);
        }
        return AjaxResult.success(kyTaskSubmitService.submitKyjTasks(kyPadInfoEntity, dataKyjVo));
    }

    /**
     * 水泵数据提交
     *
     * @return
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "水泵")
    @Transactional
    @Anonymous
    @PostMapping(value = "/shuibeng")
    public AjaxResult submitShuibeng(@ApiParam(name="'shuibeng' data",value="传入json格式",required=true)@RequestBody ShbPadToServerDTO dataShbVo) {
        if (!dataShbVo.getUploadType().equals("1") && !dataShbVo.signOk()) {
            return AjaxResult.error(SystemHttpCode.ERROR_ILLEGAL.getCode(), "非法请求");
        }
        // 平板信息
        KyPadInfo kyPadInfoEntity = kyPadInfoService.selectKyPadInfoByPadSn(dataShbVo.getPadSn());
        if (kyPadInfoEntity == null && dataShbVo.getUploadType().equals("0")) {
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND.getCode(), "非法设备");
        }
        if(dataShbVo.getUserId() == null){
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND_USER.getCode(), "仪器还未绑定用户");
        }
        // 判断平板上传数据接口类型信息
//        if(!"005".equals(dataTshjPadToServerDTO.getDevType())) {
//            return AjaxResult.error(ServiceHttpCode.MEDIA_DEVICE_TYPE_ERROR.getCode(), "非法上传");
//        }
        if(dataShbVo.getUploadType().equals("2")) {
            //根据userId获取用户信息
            SysUser sysUser = sysUserService.selectUserById(Long.parseLong(dataShbVo.getUserId()));
            kyPadInfoEntity = new KyPadInfo();
            kyPadInfoEntity.setDeptId(sysUser.getDeptId());
            kyPadInfoEntity.setUserId(sysUser.getUserId());
            kyPadInfoEntity.setPadSn(dataShbVo.getPadSn());
            //临时绑定平板数据信息
            KyDeviceInfo kyDeviceInfo = new KyDeviceInfo();
            //绑定用户信息到平板设备中
            LoginUser loginUser = CacheQrKeyUtils.getQrCache(dataShbVo.getBindKey());
            kyDeviceInfo.setDevType(dataShbVo.getDevType());
            kyDeviceInfo.setAppTypes(dataShbVo.getAppTypes());
            kyDeviceInfo.setDevNum(dataShbVo.getDevNum());
            kyDeviceInfo.setTeamUse("0");
            kyDeviceInfo.setDeptId(sysUser.getDeptId());
            kyDeviceInfo.setUserId(sysUser.getUserId());
            kyDeviceInfo.setCreateBy(sysUser.getUserName());
            kyDeviceInfoService.insertKyDeviceInfo(kyDeviceInfo);
        }
        return AjaxResult.success(kyTaskSubmitService.submitTasks(kyPadInfoEntity, dataShbVo));
    }

    /**
     * 通风机数据提交
     *
     * @return
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "通风机")
    @Transactional
    @Anonymous
    @PostMapping(value = "/tongfengji")
    public AjaxResult submitTongfengji(@ApiParam(name="'tongfengji' data",value="传入json格式",required=true)@RequestBody DataTfjPadToServerDTO dataTfjVo) {
        if (!dataTfjVo.getUploadType().equals("1") && !dataTfjVo.signOk()) {
            return AjaxResult.error(SystemHttpCode.ERROR_ILLEGAL.getCode(), "非法请求");
        }
        // 平板信息
        KyPadInfo kyPadInfoEntity = kyPadInfoService.selectKyPadInfoByPadSn(dataTfjVo.getPadSn());
        if (kyPadInfoEntity == null && dataTfjVo.getUploadType().equals("0")) {
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND.getCode(), "非法设备");
        }
        if(dataTfjVo.getUserId() == null){
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND_USER.getCode(), "仪器还未绑定用户");
        }
        // 判断平板上传数据接口类型信息
//        if(!"003".equals(dataTshjPadToServerDTO.getDevType())) {
//            return AjaxResult.error(ServiceHttpCode.MEDIA_DEVICE_TYPE_ERROR.getCode(), "非法上传");
//        }
        if(dataTfjVo.getUploadType().equals("2")) {
            //根据userId获取用户信息
            SysUser sysUser = sysUserService.selectUserById(Long.parseLong(dataTfjVo.getUserId()));
            kyPadInfoEntity = new KyPadInfo();
            kyPadInfoEntity.setDeptId(sysUser.getDeptId());
            kyPadInfoEntity.setUserId(sysUser.getUserId());
            kyPadInfoEntity.setPadSn(dataTfjVo.getPadSn());
            //临时绑定平板数据信息
            KyDeviceInfo kyDeviceInfo = new KyDeviceInfo();
            //绑定用户信息到平板设备中
            LoginUser loginUser = CacheQrKeyUtils.getQrCache(dataTfjVo.getBindKey());
            kyDeviceInfo.setDevType(dataTfjVo.getDevType());
            kyDeviceInfo.setAppTypes(dataTfjVo.getAppTypes());
            kyDeviceInfo.setDevNum(dataTfjVo.getDevNum());
            kyDeviceInfo.setTeamUse("0");
            kyDeviceInfo.setDeptId(sysUser.getDeptId());
            kyDeviceInfo.setUserId(sysUser.getUserId());
            kyDeviceInfo.setCreateBy(sysUser.getUserName());
            kyDeviceInfoService.insertKyDeviceInfo(kyDeviceInfo);
        }
        return AjaxResult.success(kyTaskSubmitService.submitTfjTasks(kyPadInfoEntity, dataTfjVo));
    }

    /**
     * 单轨吊数据提交
     *
     * @return
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "单轨吊")
    @Transactional
    @Anonymous
    @PostMapping(value = "/danguidiao")
    public AjaxResult submiDanguidiao(@ApiParam(name="'danguidiao' data",value="传入json格式",required=true)@RequestBody DataDgdPadToServerDTO dataDgdVo) {
        if (!dataDgdVo.getUploadType().equals("1") && !dataDgdVo.signOk()) {
            return AjaxResult.error(SystemHttpCode.ERROR_ILLEGAL.getCode(), "非法请求");
        }
        // 平板信息
        KyPadInfo kyPadInfoEntity = kyPadInfoService.selectKyPadInfoByPadSn(dataDgdVo.getPadSn());
        if (kyPadInfoEntity == null && dataDgdVo.getUploadType().equals("0")) {
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND.getCode(), "非法设备");
        }
        if(dataDgdVo.getUserId() == null){
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND_USER.getCode(), "仪器还未绑定用户");
        }
//        // 判断平板上传数据接口类型信息
//        if(!"00A".equals(dataDgdVo.getDevType())) {
//            return AjaxResult.error(ServiceHttpCode.MEDIA_DEVICE_TYPE_ERROR.getCode(), "非法上传");
//        }
        if(dataDgdVo.getUploadType().equals("2")) {
            //根据userId获取用户信息
            SysUser sysUser = sysUserService.selectUserById(Long.parseLong(dataDgdVo.getUserId()));
            kyPadInfoEntity = new KyPadInfo();
            kyPadInfoEntity.setDeptId(sysUser.getDeptId());
            kyPadInfoEntity.setUserId(sysUser.getUserId());
            kyPadInfoEntity.setPadSn(dataDgdVo.getPadSn());
            //临时绑定平板数据信息
            KyDeviceInfo kyDeviceInfo = new KyDeviceInfo();
            //绑定用户信息到平板设备中
            LoginUser loginUser = CacheQrKeyUtils.getQrCache(dataDgdVo.getBindKey());
            kyDeviceInfo.setDevType(dataDgdVo.getDevType());
            kyDeviceInfo.setAppTypes(dataDgdVo.getAppTypes());
            kyDeviceInfo.setDevNum(dataDgdVo.getDevNum());
            kyDeviceInfo.setTeamUse("0");
            kyDeviceInfo.setDeptId(sysUser.getDeptId());
            kyDeviceInfo.setUserId(sysUser.getUserId());
            kyDeviceInfo.setCreateBy(sysUser.getUserName());
            kyDeviceInfoService.insertKyDeviceInfo(kyDeviceInfo);
        }
        return AjaxResult.success(kyTaskSubmitService.submitDgdTasks(kyPadInfoEntity, dataDgdVo));
    }

    /**
     * 电机数据上传提交
     *
     * @return
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "电机数据上传提交")
    @Transactional
    @Anonymous
    @PostMapping(value = "/dianji")
    public AjaxResult submitDianji(@ApiParam(name="'dianji' data",value="传入json格式",required=true)@RequestBody DataDjPadToServerDTO dataDjPadToServerDTO) {
        if (!dataDjPadToServerDTO.getUploadType().equals("1") && !dataDjPadToServerDTO.signOk()) {
            return AjaxResult.error(SystemHttpCode.ERROR_ILLEGAL.getCode(), "非法请求");
        }
        // 平板信息
        KyPadInfo kyPadInfoEntity = kyPadInfoService.selectKyPadInfoByPadSn(dataDjPadToServerDTO.getPadSn());
        if (kyPadInfoEntity == null && dataDjPadToServerDTO.getUploadType().equals("0")) {
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND.getCode(), "非法设备");
        }
        if(dataDjPadToServerDTO.getUserId() == null){
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND_USER.getCode(), "仪器还未绑定用户");
        }
        // 判断平板上传数据接口类型信息
//        if(!"001".equals(dataTshjPadToServerDTO.getDevType())) {
//            return AjaxResult.error(ServiceHttpCode.MEDIA_DEVICE_TYPE_ERROR.getCode(), "非法上传");
//        }
        if(dataDjPadToServerDTO.getUploadType().equals("2")) {
            //根据userId获取用户信息
            SysUser sysUser = sysUserService.selectUserById(Long.parseLong(dataDjPadToServerDTO.getUserId()));
            kyPadInfoEntity = new KyPadInfo();
            kyPadInfoEntity.setDeptId(sysUser.getDeptId());
            kyPadInfoEntity.setUserId(sysUser.getUserId());
            kyPadInfoEntity.setPadSn(dataDjPadToServerDTO.getPadSn());
            //临时绑定平板数据信息
            KyDeviceInfo kyDeviceInfo = new KyDeviceInfo();
            //绑定用户信息到平板设备中
            LoginUser loginUser = CacheQrKeyUtils.getQrCache(dataDjPadToServerDTO.getBindKey());
            kyDeviceInfo.setDevType(dataDjPadToServerDTO.getDevType());
            kyDeviceInfo.setAppTypes(dataDjPadToServerDTO.getAppTypes());
            kyDeviceInfo.setDevNum(dataDjPadToServerDTO.getDevNum());
            kyDeviceInfo.setTeamUse("0");
            kyDeviceInfo.setDeptId(sysUser.getDeptId());
            kyDeviceInfo.setUserId(sysUser.getUserId());
            kyDeviceInfo.setCreateBy(sysUser.getUserName());
            kyDeviceInfoService.insertKyDeviceInfo(kyDeviceInfo);
        }
        return AjaxResult.success(kyTaskSubmitService.submitDjTasks(kyPadInfoEntity, dataDjPadToServerDTO));
    }

    /**
     * 架空乘人数据提交
     *
     * @return
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "架空乘人")
    @Transactional
    @Anonymous
    @PostMapping(value = "/jiakongchengren")
    public AjaxResult submitJiakongchengren(@ApiParam(name="'jiakongchengren' data",value="传入json格式",required=true)@RequestBody DataJkcrPadToServerDTO dataJkcrVo) {
        if (!dataJkcrVo.getUploadType().equals("1") && !dataJkcrVo.signOk()) {
            return AjaxResult.error(SystemHttpCode.ERROR_ILLEGAL.getCode(), "非法请求");
        }
        // 平板信息
        KyPadInfo kyPadInfoEntity = kyPadInfoService.selectKyPadInfoByPadSn(dataJkcrVo.getPadSn());
        if (kyPadInfoEntity == null && dataJkcrVo.getUploadType().equals("0")) {
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND.getCode(), "非法设备");
        }
        if(dataJkcrVo.getUserId() == null){
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND_USER.getCode(), "仪器还未绑定用户");
        }
        // 判断平板上传数据接口类型信息
//        if(!"00E".equals(dataTshjPadToServerDTO.getDevType())) {
//            return AjaxResult.error(ServiceHttpCode.MEDIA_DEVICE_TYPE_ERROR.getCode(), "非法上传");
//        }
        if(dataJkcrVo.getUploadType().equals("2")) {
            //根据userId获取用户信息
            SysUser sysUser = sysUserService.selectUserById(Long.parseLong(dataJkcrVo.getUserId()));
            kyPadInfoEntity = new KyPadInfo();
            kyPadInfoEntity.setDeptId(sysUser.getDeptId());
            kyPadInfoEntity.setUserId(sysUser.getUserId());
            kyPadInfoEntity.setPadSn(dataJkcrVo.getPadSn());
            //临时绑定平板数据信息
            KyDeviceInfo kyDeviceInfo = new KyDeviceInfo();
            //绑定用户信息到平板设备中
            LoginUser loginUser = CacheQrKeyUtils.getQrCache(dataJkcrVo.getBindKey());
            kyDeviceInfo.setDevType(dataJkcrVo.getDevType());
            kyDeviceInfo.setAppTypes(dataJkcrVo.getAppTypes());
            kyDeviceInfo.setDevNum(dataJkcrVo.getDevNum());
            kyDeviceInfo.setTeamUse("0");
            kyDeviceInfo.setDeptId(sysUser.getDeptId());
            kyDeviceInfo.setUserId(sysUser.getUserId());
            kyDeviceInfo.setCreateBy(sysUser.getUserName());
            kyDeviceInfoService.insertKyDeviceInfo(kyDeviceInfo);
        }
        return AjaxResult.success(kyTaskSubmitService.submitJkcrTasks(kyPadInfoEntity, dataJkcrVo));
    }

    /**
     * 无轨胶轮车数据提交
     *
     * @return
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "无轨胶轮车")
    @Transactional
    @Anonymous
    @PostMapping(value = "/wuguijiaolunche")
    public AjaxResult submitJiakongchengren(@ApiParam(name="'wuguijiaolunche' data",value="传入json格式",required=true)@RequestBody DataWgjlcPadToServerDTO dataWgjlcVo) {
        if (!dataWgjlcVo.getUploadType().equals("1") && !dataWgjlcVo.signOk()) {
            return AjaxResult.error(SystemHttpCode.ERROR_ILLEGAL.getCode(), "非法请求");
        }
        // 平板信息
        KyPadInfo kyPadInfoEntity = kyPadInfoService.selectKyPadInfoByPadSn(dataWgjlcVo.getPadSn());
        if (kyPadInfoEntity == null && dataWgjlcVo.getUploadType().equals("0")) {
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND.getCode(), "非法设备");
        }
        if(dataWgjlcVo.getUserId() == null){
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND_USER.getCode(), "仪器还未绑定用户");
        }
        // 判断平板上传数据接口类型信息
//        if(!"01A".equals(dataWgjlcVo.getDevType())) {
//            return AjaxResult.error(ServiceHttpCode.MEDIA_DEVICE_TYPE_ERROR.getCode(), "非法上传");
//        }
        if(dataWgjlcVo.getUploadType().equals("2")) {
            //根据userId获取用户信息
            SysUser sysUser = sysUserService.selectUserById(Long.parseLong(dataWgjlcVo.getUserId()));
            kyPadInfoEntity = new KyPadInfo();
            kyPadInfoEntity.setDeptId(sysUser.getDeptId());
            kyPadInfoEntity.setUserId(sysUser.getUserId());
            kyPadInfoEntity.setPadSn(dataWgjlcVo.getPadSn());
            //临时绑定平板数据信息
            KyDeviceInfo kyDeviceInfo = new KyDeviceInfo();
            //绑定用户信息到平板设备中
            LoginUser loginUser = CacheQrKeyUtils.getQrCache(dataWgjlcVo.getBindKey());
            kyDeviceInfo.setDevType(dataWgjlcVo.getDevType());
            kyDeviceInfo.setAppTypes(dataWgjlcVo.getAppTypes());
            kyDeviceInfo.setDevNum(dataWgjlcVo.getDevNum());
            kyDeviceInfo.setTeamUse("0");
            kyDeviceInfo.setDeptId(sysUser.getDeptId());
            kyDeviceInfo.setUserId(sysUser.getUserId());
            kyDeviceInfo.setCreateBy(sysUser.getUserName());
            kyDeviceInfoService.insertKyDeviceInfo(kyDeviceInfo);
        }
        return AjaxResult.success(kyTaskSubmitService.submitWgjlcTasks(kyPadInfoEntity, dataWgjlcVo));
    }

    /**
     * 皮带机数据提交
     *
     * @return
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "皮带机")
    @Transactional
    @Anonymous
    @PostMapping(value = "/pidaiji")
    public AjaxResult submitPidaiji(@ApiParam(name="'pidaiji' data",value="传入json格式",required=true)@RequestBody DataPidaijiPadToServerDTO dataPidaijiPadToServerDTO) {
        if (!dataPidaijiPadToServerDTO.getUploadType().equals("1") && !dataPidaijiPadToServerDTO.signOk()) {
            return AjaxResult.error(SystemHttpCode.ERROR_ILLEGAL.getCode(), "非法请求");
        }
        // 平板信息
        KyPadInfo kyPadInfoEntity = kyPadInfoService.selectKyPadInfoByPadSn(dataPidaijiPadToServerDTO.getPadSn());
        if (kyPadInfoEntity == null && dataPidaijiPadToServerDTO.getUploadType().equals("0")) {
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND.getCode(), "非法设备");
        }
        if(dataPidaijiPadToServerDTO.getUserId() == null){
            return AjaxResult.error(ServiceHttpCode.BIND_UNBOUND_USER.getCode(), "仪器还未绑定用户");
        }
        // 判断平板上传数据接口类型信息
//        if(!"01A".equals(dataWgjlcVo.getDevType())) {
//            return AjaxResult.error(ServiceHttpCode.MEDIA_DEVICE_TYPE_ERROR.getCode(), "非法上传");
//        }
        if(dataPidaijiPadToServerDTO.getUploadType().equals("2")) {
            //根据userId获取用户信息
            SysUser sysUser = sysUserService.selectUserById(Long.parseLong(dataPidaijiPadToServerDTO.getUserId()));
            kyPadInfoEntity = new KyPadInfo();
            kyPadInfoEntity.setDeptId(sysUser.getDeptId());
            kyPadInfoEntity.setUserId(sysUser.getUserId());
            kyPadInfoEntity.setPadSn(dataPidaijiPadToServerDTO.getPadSn());
            //临时绑定平板数据信息
            KyDeviceInfo kyDeviceInfo = new KyDeviceInfo();
            //绑定用户信息到平板设备中
            LoginUser loginUser = CacheQrKeyUtils.getQrCache(dataPidaijiPadToServerDTO.getBindKey());
            kyDeviceInfo.setDevType(dataPidaijiPadToServerDTO.getDevType());
            kyDeviceInfo.setAppTypes(dataPidaijiPadToServerDTO.getAppTypes());
            kyDeviceInfo.setDevNum(dataPidaijiPadToServerDTO.getDevNum());
            kyDeviceInfo.setTeamUse("0");
            kyDeviceInfo.setDeptId(sysUser.getDeptId());
            kyDeviceInfo.setUserId(sysUser.getUserId());
            kyDeviceInfo.setCreateBy(sysUser.getUserName());
            kyDeviceInfoService.insertKyDeviceInfo(kyDeviceInfo);
        }
        return AjaxResult.success(kyTaskSubmitService.submitPidaijiTasks(kyPadInfoEntity, dataPidaijiPadToServerDTO));
    }

}
